package servlet;

import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class WarehouseUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int wid =Integer.parseInt(request.getParameter("wid"));
        String wname =request.getParameter("wname");
        String wperson =request.getParameter("wperson");
        String addrss =request.getParameter("addrss");
        String statics =request.getParameter("statics");
        String sql ="UPDATE warehouse set wname=?,wperson=?,addrss=?,statics=? WHERE wid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setString(1,wname);
            ps.setString(2,wperson);
            ps.setString(3,addrss);
            ps.setString(4,statics);
            ps.setInt(5,wid);
            int up = ps.executeUpdate();
            request.getRequestDispatcher("warehouse.jsp").forward(request, response);

        } catch (SQLException e) {

            e.printStackTrace();
        } catch (ClassNotFoundException e) {

            e.printStackTrace();
        }

    }
}
